package cn.elegent.tx.feign;

import cn.elegent.ac.context.ElegentACContext;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * FeignInterceptor
 * @author: 黑马刘皇叔
 * @describe: feign接口
 * @date: 2023-9-8
 **/
@Component
@Slf4j
public class FeignInterceptor implements RequestInterceptor {

    /**
     * feign调用之前进行拦截
     * 获取用户的令牌,再将令牌封装到请求头中传递到下个微服务
     */
    @Override
    public void apply(RequestTemplate requestTemplate) {

        String chainID = ElegentACContext.get();
        log.info("链路id:{} ",chainID);
        if(chainID!=null){
            requestTemplate.header(ElegentACTXConstant.CHAINID_HEAD, chainID);
        }
    }


}